package fr.mywiki.view.web.struts.form.home;

import java.rmi.RemoteException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.ejb.FinderException;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionForm;

import fr.mywiki.business.entry.EntryListManager;
import fr.mywiki.business.entry.EntryLite;
import fr.mywiki.business.login.LoginManager;
import fr.mywiki.view.array.ArrayController;
import fr.mywiki.view.array.ArrayDefinition;
import fr.mywiki.view.web.struts.form.ListForm;

public class HomeForm extends ActionForm implements ListForm {
	private static final long serialVersionUID = 1L;

	private String idElement;
	
	/**
	 * Loads (if necessary) and returns a ArrayController for all the entries.
	 * 
	 * @return a <code>ArrayController</code> object.
	 */
	public static ArrayController getEntriesController(HttpServletRequest request)
      throws RemoteException, SQLException, FinderException {
		List entries = new ArrayList(EntryListManager.getEntries(LoginManager
				.getLoggedUser(request.getSession())));
		ArrayController entriesController = new ArrayController(ArrayDefinition
				.getArrayDefinition(EntryLite.TYPE_ENT), entries);

		return entriesController;
	}

	public String getIdElement() {
		return idElement;
	}

	public void setIdElement(String idElement) {
		this.idElement = idElement;
	}
}
